package com.isunland.managesystem.ui;

import android.os.Bundle;
import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.DictionaryTreeContent;
import java.util.ArrayList;
import java.util.HashMap;

public class ProjectPropertyDialogFrament extends BaseNetworkDialogFragment {

  protected static String EXTRA_VALUE =
      "com.isunland.managesystem.ui.ProjectPropertyDialogFrament.EXTRA_VALUE";

  protected static String property = "projectProperty";
  protected static String kind = "projectKindCode";
  protected static String type = "SDefProKind";
  protected static String regDate = "regDate";
  private String dictFlg = "";

  @Override public void onCreate(Bundle savedInstanceState) {
    dictFlg = (String) getArguments().getSerializable(EXTRA_VALUE);
    super.onCreate(savedInstanceState);
  }

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();

    DictionaryTreeContent[] dataList = new Gson().fromJson(arg0, DictionaryTreeContent[].class);

    // List<DictionaryTreeContent> dataList=trafToolOriginal.getDataList();

    if (dataList == null || dataList.length == 0) {

      return null;
    }
    for (int i = 0; i < dataList.length; i++) {
      list.add(new CustomerDialog(dataList[i].getName(), dataList[i].getCustomAttrs()));
    }
    if (!regDate.equals(dictFlg)) {
      list.add(new CustomerDialog("全部", ""));
    }

    return list;
  }

  @Override public String getUrl() {

    return ApiConst.URL_DATA_DICTIONARY_LIST;
  }

  @Override public HashMap<String, String> getparameters() {
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("dictFlg", dictFlg);
    params.put("andriodUser", "true");
    params.put("memCode", CurrentUser.newInstance(getActivity()).getMemberCode());
    return params;
  }

  protected static ProjectPropertyDialogFrament newInstance(String dictFlg) {
    Bundle args = new Bundle();
    args.putSerializable(EXTRA_VALUE, dictFlg);
    ProjectPropertyDialogFrament fragment = new ProjectPropertyDialogFrament();
    fragment.setArguments(args);
    return fragment;
  }
}
